package com.thinta.wind.ui.splash

import android.content.Intent
import android.view.animation.AlphaAnimation
import android.view.animation.Animation
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModelProvider
import com.thinta.wind.R
import com.thinta.wind.base.BaseActivity
import com.thinta.wind.base.BaseModel
import com.thinta.wind.base.ViewModelFactory
import com.thinta.wind.ui.login.LoginActivity
import com.thinta.wind.ui.main.MainActivity
import kotlinx.android.synthetic.main.activity_splash.*

class SplashActivity : BaseActivity<BaseModel, ViewDataBinding>() {

    private var alphaAnimation : AlphaAnimation? = null

    override fun getModelFactory(): ViewModelProvider.NewInstanceFactory = ViewModelFactory()

    override fun viewModelClass(): Class<BaseModel> = BaseModel::class.java

    override fun startListenerData() {
        alphaAnimation?.setAnimationListener(object : Animation.AnimationListener{

            override fun onAnimationStart(p0: Animation?) {

            }

            override fun onAnimationEnd(p0: Animation?) {
                startActivity(Intent(this@SplashActivity, LoginActivity::class.java))
            }

            override fun onAnimationRepeat(p0: Animation?) {

            }
        })
    }

    override fun initView() {
        alphaAnimation = AlphaAnimation(0.3f, 0.1f)
        alphaAnimation?.duration = 2000
        startListenerData()
        splash_layout.startAnimation(alphaAnimation)
    }

    override fun getLayoutRes(): Int = R.layout.activity_splash
}
